package com.lm.tika.example;

import org.apache.tika.Tika;
import org.apache.tika.metadata.Metadata;

import java.io.File;
import java.io.FileInputStream;

public class ParseWord {
    public static void main(String[] args) {
        try {
            File file = new File("example.docx");
            FileInputStream inputStream = new FileInputStream(file);

            Tika tika = new Tika();
            Metadata metadata = new Metadata();
            String content = tika.parseToString(inputStream, metadata);

            System.out.println("📄内容: ");
            System.out.println(content);

            System.out.println("\n📜元数据: ");
            for (String name : metadata.names()) {
                System.out.println(name + ": " + metadata.get(name));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
